#pragma once

#include <i_component_def.h>

class CComponentFactory;
class COMPONENT_DLL_EXPORT CComponent
{
public:
	CComponent();
	virtual ~CComponent();

	void SetFactory(CComponentFactory& factory);

	CComponentFactory* GetFactory();

	IComponentContainer* GetContainer();

	int Install(IComponentContainer& container, ComID com_id);

	void Uninstall();

	int Start();

	void Stop();

	ComID getComID() const {
		return m_comid;
	}

	int GetStatus() const {
		return m_status;
	}
protected:
	virtual int _OnInstall();
	virtual void _OnUninstall();
	virtual int _OnStart();
	virtual void _OnStop();
protected:
	void _AddDependence(const IComponentHolderPtrList& dependences);
	void _AddDependence(IComponentHolder& dependence);
private:
	// ECOMPONENT_STATUS
	int m_status;
	ComID m_comid;
	IComponentHolderPtrSet* m_dependences;
	CComponentFactory* m_factory;
	IComponentContainer* m_container;
};
